package com.rw.admin.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {
    @Value("${app.rabbitmq.queueName1}")
    String queueName1;
    @Value("${app.rabbitmq.queueName2}")
    String queueName2;
    @Value("${app.rabbitmq.exchangeName}")
    String exchangeName;

    @Bean
    public Queue Queue1() {
        return new Queue(queueName1, false, false, true);
    }

    @Bean
    public Queue Queue2() {
        return new Queue(queueName2, false, false, true);
    }

    @Bean
    public TopicExchange TopicExchange() {
        return new TopicExchange(exchangeName, false, true);
    }

    @Bean
    public Binding ExchangeBinding1(TopicExchange topicExchange, @Qualifier("Queue1") Queue
            queue) {
        return BindingBuilder.bind(queue).to(topicExchange).with("*.*.java");
    }

    @Bean
    public Binding ExchangeBinding2(TopicExchange topicExchange, @Qualifier("Queue2") Queue
            queue) {
        return BindingBuilder.bind(queue).to(topicExchange).with("#.mail");
    }
}
